Reputation: 129
I am trying to resize my chrome extensions window but I do not know how to do it.
document.write('<div class="card" id="main-card" style="width: 18rem; height: 20rem;">')
document.write('<img class="card-img-top" src="..." alt="Card image cap">')
document.write('<div class="card-body">')
document.write('<h5 class="card-title">Card title</h5>')
document.write('<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card\'s content.</p>')
document.write('<button id="test" class="btn btn-primary">Go somewhere</button>')
document.write('</div>')
document.write('</div> ')
document.getElementById("test").onclick = function() {
document.getElementById("main-card").style.height = "10rem"
}
<html>
<head>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-giJF6kkoqNQ00vy+HMDP7azOuL0xtbfIcaT9wjKHr8RbDVddVHyTfAAsrekwKmP1" crossorigin="anonymous">
<script src="index.js"></script>
</head>
<body>
</body>
</html>
manifest.json { "name": "Test", "version": "1.0", "description": "This extension", "author": "Test", "browser_action": { "default_popup": "index.html", "default_title": "WRB" }, "manifest_version": 2 }
Upvotes: 0
Views: 2142
Reputation: 1
For the given requirement, the HTML min-width property can be set to a minimum fixed size, and the height can be set to fit-content as given below.
CSS:
html {
min-width: 400px;
height: fit-content;
}
Upvotes: 0
Reputation: 560
To resize the popup window you just need to resize your content. The best way to do that is by editing the width and/or height of your <body>
element.
For example:
document.body.style.width = '600px';
If that isn't working make sure you have a DOCTYPE declaration as per this question.
EDIT:
Now that I see the code you are using here is an updated solution.
document.body.innerHTML +=
`<div class="card" id="main-card" style="width: 18rem; height: 20rem;"><img class="card-img-top" src="..." alt="Card image cap">
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card\'s content.</p>
<button id="test" class="btn btn-primary">Go somewhere</button>
</div>
</div>`;
document.getElementById("test").onclick = function() {
document.getElementById("main-card").style.height = "10rem";
document.documentElement.style.height = "10rem";
}
<html>
<head>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-giJF6kkoqNQ00vy+HMDP7azOuL0xtbfIcaT9wjKHr8RbDVddVHyTfAAsrekwKmP1" crossorigin="anonymous">
</head>
<body>
<script src="index.js"></script>
</body>
</html>
It looks like the problem you were having is that the documentElement
(Your <html>
tag) was never resizing when the rest of the content shrunk. I just added document.documentElement.style.height = "10rem";
to the callback function to also decrease the size of the document.
In addition but not related to this specific issue, I would not recommend using document.write()
because it will cause you problems later down the line especially with overwriting your original page content. To fix this I appended your HTML tags to the innerHTML
of your document's <body>
. I also moved the <script>
tag for your popup script to the body so that it runs only after the body has been loaded.
How to Find A Problematic Element
Since you mentioned that while this works on the sample code, it does not in your actual code here is how you can go about finding the problematic element(s) in your actual project.
Here is a GIF showcasing how to open and view elements in dev tools:
Upvotes: 2