Why does my Chrome extension's browser action popup not show? - javascript

Here is my manifest.json file:
{
"browser_action" :
{
"default_icon" : "Assets/Chromium logosu.png",
"default_popup" : "main.html"
},
"description" : "Bu eklenti, Chromium'un güncelleştirmelerini denetler ve yükler.",
"manifest_version" : 2,
"name" : "Chromium Güncelleştirici",
"version" : "1.0"
}
And here is my main.html file:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Page</title>
<meta name="generator" content="WYSIWYG Web Builder 16 - https://www.wysiwygwebbuilder.com">
<link href="Chromium_Güncelleştirici_Eklenti_Projesi.css" rel="stylesheet">
<link href="main.css" rel="stylesheet">
</head>
<body>
<div id="wb_Image1" style="position:absolute;left:0px;top:0px;width:320px;height:50px;z-index:0;">
<img src="Assets/Başlık.png" id="Image1" alt=""></div>
<div id="wb_Image7" style="position:absolute;left:0px;top:160px;width:320px;height:35px;z-index:1;">
<img src="Assets/Telif Hakkı Metni.png" id="Image7" alt=""></div>
<div id="wb_Image2" style="position:absolute;left:0px;top:50px;width:320px;height:37px;z-index:2;">
<img src="Assets/Güncelleştirmeleri Denetle (Pasif).png" id="Image2" alt=""></div>
<div id="wb_Image3" style="position:absolute;left:0px;top:87px;width:320px;height:36px;z-index:3;">
<img src="Assets/Ayarlar (Pasif).png" id="Image3" alt=""></div>
<div id="wb_Image4" style="position:absolute;left:0px;top:123px;width:320px;height:37px;z-index:4;">
<img src="Assets/Hakkında (Pasif).png" id="Image4" alt=""></div>
</body>
</html>
When I click the extension's button, I get this:
My extension's popup menu
Actually, my popup page should be shown like this:
The UI of my popup file
So, what should I do in order to fix this issue?

Popup html takes height and width from the content of the html loaded.
In your case, all div elements inside body are position:absolute, which results in zero height and width to body tag, and hence the Popup UI appears as a small box when loaded as browser action popup.
You can verify this behaviour by giving fixed height or width to tag in your css.
Why it appears fine when main.html loaded directly to browser?
It actually appears fine, but over here as well the body results in zero height, but because the viewport is not depended on the content of body, it shows the content outside the body as depicted in sample screenshot below.
How to fix?
Fix your CSS such that body gets overall height of the actual content that you need to show. Not sure why every element here you have placed as position absolute, I feel you can avoid that approach and still get the UI as expected by you.
Worst case, you can hardcode the body with fixed height and width of what you need the actual popup html size to be.

#Junaid Hamza
Ok, I have fixed my issue via doing these things:
1- First of all, I have removed all of "position:absolute;"s. But, when I did this, I encountered another issue. This time, the order of images was broken.
2- In order to fix the second issue, I have used a weird method. I have merged last three images into one image.
Anyway, thank you for your answer.😊

Related

How to resize chrome extension window in javascript?

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/bootstrap#5.0.0-beta1/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
}
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/bootstrap#5.0.0-beta1/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.
Open your popup window.
Right click within the window and click inspect.
This will bring up dev tools.
Hover over your elements in the elements panel, they will be highlighted.
Look for an element that is taking up more space than your desired height. It is best to start from the outermost element and work your way in.
Once you identify an element that is causing an issue, try changing the size of that element on the click of the button to test if the window resizes with it.
If it works, good news, you found your problem. If it doesn't, repeat steps 4-6 with the next outermost element until you find the element that is causing problems.
Here is a GIF showcasing how to open and view elements in dev tools:
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;
}

Could we replace images with srcset?

There is something that I have to fix it about changing img on mobil and tablet with another different images I couldn't fix it with jQuery (I'm a beginner with jQuery) and I'm trying to do it with html5.
Is there any way to change the image on the tablet and mobile versions with srcset? What can I do? Why is my code not working as expected? How can I change img src on 768px and 480px with jQuery? The image will be changed dynamically, that is why I don't want to do with just css (media queries).
This is my another code
<html lang="en">
<head>
<meta charset="UTF-8" />
</head>
<body>
<img src="http://yurtici.anitur.com.tr/musteri/ingoing/2017/htm/img/1.jpg"
srcset="http://yurtici.anitur.com.tr/musteri/ingoing/2017/htm/img/2.jpg 1000w, http://yurtici.anitur.com.tr/musteri/ingoing/2017/htm/img/3.jpg 768w,http://yurtici.anitur.com.tr/musteri/ingoing/2017/htm/img/4.jpg 400w">
</body>
</html>
add style to the image so that it is always 100% of the screen-width
<img src="http://yurtici.anitur.com.tr/musteri/ingoing/2017/htm/img/1.jpg"
srcset="http://yurtici.anitur.com.tr/musteri/ingoing/2017/htm/img/2.jpg 1000w, http://yurtici.anitur.com.tr/musteri/ingoing/2017/htm/img/3.jpg 768w,http://yurtici.anitur.com.tr/musteri/ingoing/2017/htm/img/4.jpg 400w" style="width:100%">

embed-responsive shows white border in bottom

I have a webpage, that shows another html page using iframe. Please see my code below.
<html>
<head>
<title>DotWifi</title>
<meta http-equiv="Pragma" content="no-cache">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
</head>
<body>
<div class="embed-responsive embed-responsive-4by3">
<iframe class="embed-responsive-item" src="http://www.xxxx.com/xxxxxx/xxpage?xxxId=123&tok=$tok&authaction=$authtarget"></iframe>
</div>
</body>
</html>
I am try to show a responsive webpage using iframe using embed-responsive-item class. But it shows a white border in bottom. Please see the below image.
That's not a border, it's simply the background of the body.
The iframe's parent div, embed-responsive-4by3 is supposed to have a width to height ratio of 4 by 3. That's what this class does! So if the width is 416 pixels (the width of the window) then the height becomes 312 pixels.
That's all there is to it.
If you don't want that, the solution is to remove the embed-responsive-4by3 class from the div.
Or, if all your page ever does is show another page in an iframe, you can dispense with Bootstrap altogether and put only the iframe on the page!

Div size differes when viewport is used

take a look at this site www.naamdesigns.com
view this site with desktop and also with mobile. In mobile, the header div in blue does not fit the screen entirely, it covers only 50%.
why this problem occur?
Why did you set overflow-x: hidden; on body tag? I guess on mobile 100% width is only the visible part, where the whole content doesn't fit, but just half of it.
lets try to put this in your head tag:
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
Added :
this is my idea, i dont know it's would works. Lets make a container to wrap all yor contents.
<body>
<div id="wrapper" style="width:100%">
<div id="your_header"style="width:100%"></div>
<div id="your_body" style="width:100%"></div>
</div>
</body>

HTML rollover button image: how to do with Internet Explorer?

i've this simple piece of code that don't work in Internet Explorer, but do work in Chrome, Firefox etc.
It is a simple button image 'rollover' .
<html>
<head>
</head>
<body>
<img src="p1.png" name="img1" onMouseOver="document.images[0].src='p2.png'" onMouseOut="document.images[0].src='p1.png'" ></a>
</body>
</html>
What's wrong in IE 6,7,8 ?
Change your code to this:
<html>
<head>
</head>
<body>
<img src="p1.png" name="img1" onMouseOver="this.src='p2.png'" onMouseOut="this.src='p1.png'" />
</body>
</html>
Also, I if your HTML page contains more data the the HTML page you've showed in your question, I suggest you put this code in the beginning of the <body> in order to preload the rollover image so there will be no delay when you want the rollover to work (otherwise, the rollover image will be downloaded to the user's device only when he hovers the image, causing a slight delay to the rollover (depending on the onMouseOver image size)):
<img src="p2.png" class="hiddenPic" />
<!-- loading (hidden) rollover image before all the other page data -->
And add the CSS hiddenPic class code: .hiddenPic { display: none; }
Other methods to preload the rollover image can be done using CSS or the JavaScript onLoad event handler.
onmouseover="this.src='p2.png'"
Use this instead of document.images....
Another method (works if you need to rollover change something else as well):
<img src="p1.png" name="img3" id="img3" onMouseOver="document.getElementById('img3').src='p2.png'" onMouseOut="document.getElementById('img3').src='p1.png'" >
http://jsfiddle.net/DNtUY/5/ (3 examples, yours, Said's, this one).
PS. Your open tag is <img ...> but the close tag is </a>
Maybe if the images are not that heavy, you might try a different approach like declaring both images and hide one of them. Then with javascript when you roll over the visible image, you hide it and show the other one.
Perfectly working code for your question mr.Stighy:
<html>
<head>
<style type="text/css">
</head>
<body>
<img src="../a_b_c/a.jpg" alt="" onMouseOver="this.src='b.jpg'" onMouseOut="this.src='a.jpg'" onClick="this.src='c.jpg'" class="style1"></a>
</body>
</html>
I think we messed up with the images, that's it... p.s. Giulio is waching you.

Categories

Resources