admin管理员组

文章数量:1325761

I would like to resize the pagewrapper div with javascript. I have chrome and would like to use it as userscript. Here is the site link: . I want to take the pagewrapper to 100% width. I have the following code:

// ==UserScript==
// @match /*
// ==/UserScript==

function addJQuery(callback) {
var script = document.createElement("script");
script.setAttribute("src", ".4.2/jquery.min.js");
script.addEventListener('load', function() {
var script = document.createElement("script");
script.textContent = "(" + callback.toString() + ")();";
document.body.appendChild(script);
}, false);
document.body.appendChild(script);
}

function pagewrapper() {
document.getElementById('pagewrapper').style.Width = "100%";
}

addJQuery(pagewrapper);

I would like to resize the pagewrapper div with javascript. I have chrome and would like to use it as userscript. Here is the site link: http://clanbase.ggl.. I want to take the pagewrapper to 100% width. I have the following code:

// ==UserScript==
// @match http://clanbase.ggl./*
// ==/UserScript==

function addJQuery(callback) {
var script = document.createElement("script");
script.setAttribute("src", "http://ajax.googleapis./ajax/libs/jquery/1.4.2/jquery.min.js");
script.addEventListener('load', function() {
var script = document.createElement("script");
script.textContent = "(" + callback.toString() + ")();";
document.body.appendChild(script);
}, false);
document.body.appendChild(script);
}

function pagewrapper() {
document.getElementById('pagewrapper').style.Width = "100%";
}

addJQuery(pagewrapper);
Share Improve this question edited Oct 7, 2012 at 12:45 Hovercraft Full Of Eels 285k25 gold badges266 silver badges388 bronze badges asked Oct 7, 2012 at 12:43 Zsolt JanesZsolt Janes 8402 gold badges9 silver badges26 bronze badges 4
  • 1 Consider changing tags here from java to javascript. They are quite different programming languages. Edit: never mind, I'll do it for you! – Hovercraft Full Of Eels Commented Oct 7, 2012 at 12:44
  • I believe, width needs to start with lowercase w. In addition, if you're already loading jQuery, why not just do $('#pagewrapper').css('width','100%');? – Aleks G Commented Oct 7, 2012 at 12:49
  • Also, you'll want to wrap that in the in the domready or load event, so $(document).ready(pagewrapper); – hobberwickey Commented Oct 7, 2012 at 12:52
  • 1 Sorry but I'm not javascript coder I found some scripts. – Zsolt Janes Commented Oct 7, 2012 at 13:12
Add a ment  | 

1 Answer 1

Reset to default 5

One thing to note is that non-absolutely positioned divider elements automatically take up 100% of the width, so you might not need to do anything. Just try removing the width property from the pagewrapper element (in the CSS) and see if it works. You could also try overriding the width property:

#pagewrapper {
    width:100%;
}

If setting CSS isn't an option for whatever reason, this script should suffice:

function pagewrapper() {
    document.getElementById('pagewrapper').style.width = "100%";
}

本文标签: How to resize div width with javascriptStack Overflow