Need a javascript solution to completely hide a portion of code in different screen devices
I'm trying to inegrate this javascript section with the correct width on mobile, desktop and tablet, so i wrote this:
this appears on mobile (using @media (min-width:...) in css)
<p align="center">News<script language="JavaScript" type="text/javascript" charset="iso-8859-1" src="//www.intopic.it/iframe.php?cat=fonti-rinnovabili&rootcat=tecnologia&type=2&bgcolor=FFFFFF&bdcolor=FFFFFF&lcolor=666666&font=1&fontsize=13&box=1050&window=1"></script></p>
this appears on tablet (using @media (min-width:...) in css)
<p align="center">News<script language="JavaScript" type="text/javascript" charset="iso-8859-1" src="//www.intopic.it/iframe.php?cat=fonti-rinnovabili&rootcat=tecnologia&type=2&bgcolor=FFFFFF&bdcolor=FFFFFF&lcolor=666666&font=1&fontsize=13&box=1050&window=1"></script></p>
this appears on desktop (using @media (min-width:...) in css)
<p align="center">News<script language="JavaScript" type="text/javascript" charset="iso-8859-1" src="//www.intopic.it/iframe.php?cat=fonti-rinnovabili&rootcat=tecnologia&type=2&bgcolor=FFFFFF&bdcolor=FFFFFF&lcolor=666666&font=1&fontsize=13&box=1050&window=1"></script></p>
The problem is due to the variable "box" that is actually read 3 times by the browser, as each portion of code for mobile, tablet and pc are present and readable by the browser, it gets the last box value wich sets the width to 250 that is ok for mobile, but not for desktop and tablet, so i need something to show the only portion of code that fits the device every time dynamically, how can i do ?
javascript html device-orientation cross-device
add a comment |
I'm trying to inegrate this javascript section with the correct width on mobile, desktop and tablet, so i wrote this:
this appears on mobile (using @media (min-width:...) in css)
<p align="center">News<script language="JavaScript" type="text/javascript" charset="iso-8859-1" src="//www.intopic.it/iframe.php?cat=fonti-rinnovabili&rootcat=tecnologia&type=2&bgcolor=FFFFFF&bdcolor=FFFFFF&lcolor=666666&font=1&fontsize=13&box=1050&window=1"></script></p>
this appears on tablet (using @media (min-width:...) in css)
<p align="center">News<script language="JavaScript" type="text/javascript" charset="iso-8859-1" src="//www.intopic.it/iframe.php?cat=fonti-rinnovabili&rootcat=tecnologia&type=2&bgcolor=FFFFFF&bdcolor=FFFFFF&lcolor=666666&font=1&fontsize=13&box=1050&window=1"></script></p>
this appears on desktop (using @media (min-width:...) in css)
<p align="center">News<script language="JavaScript" type="text/javascript" charset="iso-8859-1" src="//www.intopic.it/iframe.php?cat=fonti-rinnovabili&rootcat=tecnologia&type=2&bgcolor=FFFFFF&bdcolor=FFFFFF&lcolor=666666&font=1&fontsize=13&box=1050&window=1"></script></p>
The problem is due to the variable "box" that is actually read 3 times by the browser, as each portion of code for mobile, tablet and pc are present and readable by the browser, it gets the last box value wich sets the width to 250 that is ok for mobile, but not for desktop and tablet, so i need something to show the only portion of code that fits the device every time dynamically, how can i do ?
javascript html device-orientation cross-device
2
so just document.write out the script tag after reading the page size
– epascarello
Nov 19 '18 at 14:46
I'm not sure I understand; those three snippets appear to be identical. Are you including all three in the same document? Why not just resize/style the samep
in the css according to the min-width?
– dgeare
Nov 19 '18 at 14:50
Please provide full media queries. Avoid using javascript when not necessary.
– Edwin Dijas Chiwona
Nov 19 '18 at 14:56
2
Addmax-width
to your media queries.
– nvioli
Nov 19 '18 at 15:03
how can i document.write out() the code if the src it is an attribute of the <script> tag ?
– Mxmx88
Nov 19 '18 at 16:43
add a comment |
I'm trying to inegrate this javascript section with the correct width on mobile, desktop and tablet, so i wrote this:
this appears on mobile (using @media (min-width:...) in css)
<p align="center">News<script language="JavaScript" type="text/javascript" charset="iso-8859-1" src="//www.intopic.it/iframe.php?cat=fonti-rinnovabili&rootcat=tecnologia&type=2&bgcolor=FFFFFF&bdcolor=FFFFFF&lcolor=666666&font=1&fontsize=13&box=1050&window=1"></script></p>
this appears on tablet (using @media (min-width:...) in css)
<p align="center">News<script language="JavaScript" type="text/javascript" charset="iso-8859-1" src="//www.intopic.it/iframe.php?cat=fonti-rinnovabili&rootcat=tecnologia&type=2&bgcolor=FFFFFF&bdcolor=FFFFFF&lcolor=666666&font=1&fontsize=13&box=1050&window=1"></script></p>
this appears on desktop (using @media (min-width:...) in css)
<p align="center">News<script language="JavaScript" type="text/javascript" charset="iso-8859-1" src="//www.intopic.it/iframe.php?cat=fonti-rinnovabili&rootcat=tecnologia&type=2&bgcolor=FFFFFF&bdcolor=FFFFFF&lcolor=666666&font=1&fontsize=13&box=1050&window=1"></script></p>
The problem is due to the variable "box" that is actually read 3 times by the browser, as each portion of code for mobile, tablet and pc are present and readable by the browser, it gets the last box value wich sets the width to 250 that is ok for mobile, but not for desktop and tablet, so i need something to show the only portion of code that fits the device every time dynamically, how can i do ?
javascript html device-orientation cross-device
I'm trying to inegrate this javascript section with the correct width on mobile, desktop and tablet, so i wrote this:
this appears on mobile (using @media (min-width:...) in css)
<p align="center">News<script language="JavaScript" type="text/javascript" charset="iso-8859-1" src="//www.intopic.it/iframe.php?cat=fonti-rinnovabili&rootcat=tecnologia&type=2&bgcolor=FFFFFF&bdcolor=FFFFFF&lcolor=666666&font=1&fontsize=13&box=1050&window=1"></script></p>
this appears on tablet (using @media (min-width:...) in css)
<p align="center">News<script language="JavaScript" type="text/javascript" charset="iso-8859-1" src="//www.intopic.it/iframe.php?cat=fonti-rinnovabili&rootcat=tecnologia&type=2&bgcolor=FFFFFF&bdcolor=FFFFFF&lcolor=666666&font=1&fontsize=13&box=1050&window=1"></script></p>
this appears on desktop (using @media (min-width:...) in css)
<p align="center">News<script language="JavaScript" type="text/javascript" charset="iso-8859-1" src="//www.intopic.it/iframe.php?cat=fonti-rinnovabili&rootcat=tecnologia&type=2&bgcolor=FFFFFF&bdcolor=FFFFFF&lcolor=666666&font=1&fontsize=13&box=1050&window=1"></script></p>
The problem is due to the variable "box" that is actually read 3 times by the browser, as each portion of code for mobile, tablet and pc are present and readable by the browser, it gets the last box value wich sets the width to 250 that is ok for mobile, but not for desktop and tablet, so i need something to show the only portion of code that fits the device every time dynamically, how can i do ?
javascript html device-orientation cross-device
javascript html device-orientation cross-device
asked Nov 19 '18 at 14:41
Mxmx88Mxmx88
113
113
2
so just document.write out the script tag after reading the page size
– epascarello
Nov 19 '18 at 14:46
I'm not sure I understand; those three snippets appear to be identical. Are you including all three in the same document? Why not just resize/style the samep
in the css according to the min-width?
– dgeare
Nov 19 '18 at 14:50
Please provide full media queries. Avoid using javascript when not necessary.
– Edwin Dijas Chiwona
Nov 19 '18 at 14:56
2
Addmax-width
to your media queries.
– nvioli
Nov 19 '18 at 15:03
how can i document.write out() the code if the src it is an attribute of the <script> tag ?
– Mxmx88
Nov 19 '18 at 16:43
add a comment |
2
so just document.write out the script tag after reading the page size
– epascarello
Nov 19 '18 at 14:46
I'm not sure I understand; those three snippets appear to be identical. Are you including all three in the same document? Why not just resize/style the samep
in the css according to the min-width?
– dgeare
Nov 19 '18 at 14:50
Please provide full media queries. Avoid using javascript when not necessary.
– Edwin Dijas Chiwona
Nov 19 '18 at 14:56
2
Addmax-width
to your media queries.
– nvioli
Nov 19 '18 at 15:03
how can i document.write out() the code if the src it is an attribute of the <script> tag ?
– Mxmx88
Nov 19 '18 at 16:43
2
2
so just document.write out the script tag after reading the page size
– epascarello
Nov 19 '18 at 14:46
so just document.write out the script tag after reading the page size
– epascarello
Nov 19 '18 at 14:46
I'm not sure I understand; those three snippets appear to be identical. Are you including all three in the same document? Why not just resize/style the same
p
in the css according to the min-width?– dgeare
Nov 19 '18 at 14:50
I'm not sure I understand; those three snippets appear to be identical. Are you including all three in the same document? Why not just resize/style the same
p
in the css according to the min-width?– dgeare
Nov 19 '18 at 14:50
Please provide full media queries. Avoid using javascript when not necessary.
– Edwin Dijas Chiwona
Nov 19 '18 at 14:56
Please provide full media queries. Avoid using javascript when not necessary.
– Edwin Dijas Chiwona
Nov 19 '18 at 14:56
2
2
Add
max-width
to your media queries.– nvioli
Nov 19 '18 at 15:03
Add
max-width
to your media queries.– nvioli
Nov 19 '18 at 15:03
how can i document.write out() the code if the src it is an attribute of the <script> tag ?
– Mxmx88
Nov 19 '18 at 16:43
how can i document.write out() the code if the src it is an attribute of the <script> tag ?
– Mxmx88
Nov 19 '18 at 16:43
add a comment |
2 Answers
2
active
oldest
votes
I Solved Writing This:
<script type="text/javascript">
if(window.innerWidth>1024){
document.write('x3Cscript language="JavaScript" type="text/javascript" charset="iso-8859-1" src="//www.intopic.it/iframe.php?cat=fonti-rinnovabili&rootcat=tecnologia&type=2&bgcolor=FFFFFF&bdcolor=FFFFFF&lcolor=666666&font=1&fontsize=13&box=1024&window=1"x3C/script>');
}else if(window.innerWidth>600){document.write('x3Cscript language="JavaScript" type="text/javascript" charset="iso-8859-1" src="//www.intopic.it/iframe.php?cat=fonti-rinnovabili&rootcat=tecnologia&type=2&bgcolor=FFFFFF&bdcolor=FFFFFF&lcolor=666666&font=1&fontsize=13&box=600&window=1"x3C/script>');}
else{
document.write('x3Cscript language="JavaScript" type="text/javascript" charset="iso-8859-1" src="//www.intopic.it/iframe.php?cat=fonti-rinnovabili&rootcat=tecnologia&type=2&bgcolor=FFFFFF&bdcolor=FFFFFF&lcolor=666666&font=1&fontsize=13&box=250&window=1"x3C/script>');}
</script>
Partially solved, now anything is visible below this piece of code, I think there's something inside the document.write() expressions that if executed, it prevents the rest of the code to be displayed, if i write a simple <h1>hello</h1> inside that document.write(), everything works fine....
– Mxmx88
Nov 20 '18 at 9:10
add a comment |
Try:
var source_url,
script_element = document.createElement("script");
if(window.innerWidth > 1024) {
script_element.src = "1024_script_source_url";
console.log('loaded 1024 url, window width', window.innerWidth);
} else if (window.innerWidth > 600) {
script_element.src = "600_script_source_url";
console.log('loaded 1024 url, window width', window.innerWidth);
}
document.head.append(script_element);
alert('done, window width' + window.innerWidth);
You'll probably want to subscribe to window resize event so...
window.onresize = function(event) {
//do something
};
why do you declare var source_url ?
– Mxmx88
Nov 19 '18 at 16:21
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53376983%2fneed-a-javascript-solution-to-completely-hide-a-portion-of-code-in-different-scr%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
I Solved Writing This:
<script type="text/javascript">
if(window.innerWidth>1024){
document.write('x3Cscript language="JavaScript" type="text/javascript" charset="iso-8859-1" src="//www.intopic.it/iframe.php?cat=fonti-rinnovabili&rootcat=tecnologia&type=2&bgcolor=FFFFFF&bdcolor=FFFFFF&lcolor=666666&font=1&fontsize=13&box=1024&window=1"x3C/script>');
}else if(window.innerWidth>600){document.write('x3Cscript language="JavaScript" type="text/javascript" charset="iso-8859-1" src="//www.intopic.it/iframe.php?cat=fonti-rinnovabili&rootcat=tecnologia&type=2&bgcolor=FFFFFF&bdcolor=FFFFFF&lcolor=666666&font=1&fontsize=13&box=600&window=1"x3C/script>');}
else{
document.write('x3Cscript language="JavaScript" type="text/javascript" charset="iso-8859-1" src="//www.intopic.it/iframe.php?cat=fonti-rinnovabili&rootcat=tecnologia&type=2&bgcolor=FFFFFF&bdcolor=FFFFFF&lcolor=666666&font=1&fontsize=13&box=250&window=1"x3C/script>');}
</script>
Partially solved, now anything is visible below this piece of code, I think there's something inside the document.write() expressions that if executed, it prevents the rest of the code to be displayed, if i write a simple <h1>hello</h1> inside that document.write(), everything works fine....
– Mxmx88
Nov 20 '18 at 9:10
add a comment |
I Solved Writing This:
<script type="text/javascript">
if(window.innerWidth>1024){
document.write('x3Cscript language="JavaScript" type="text/javascript" charset="iso-8859-1" src="//www.intopic.it/iframe.php?cat=fonti-rinnovabili&rootcat=tecnologia&type=2&bgcolor=FFFFFF&bdcolor=FFFFFF&lcolor=666666&font=1&fontsize=13&box=1024&window=1"x3C/script>');
}else if(window.innerWidth>600){document.write('x3Cscript language="JavaScript" type="text/javascript" charset="iso-8859-1" src="//www.intopic.it/iframe.php?cat=fonti-rinnovabili&rootcat=tecnologia&type=2&bgcolor=FFFFFF&bdcolor=FFFFFF&lcolor=666666&font=1&fontsize=13&box=600&window=1"x3C/script>');}
else{
document.write('x3Cscript language="JavaScript" type="text/javascript" charset="iso-8859-1" src="//www.intopic.it/iframe.php?cat=fonti-rinnovabili&rootcat=tecnologia&type=2&bgcolor=FFFFFF&bdcolor=FFFFFF&lcolor=666666&font=1&fontsize=13&box=250&window=1"x3C/script>');}
</script>
Partially solved, now anything is visible below this piece of code, I think there's something inside the document.write() expressions that if executed, it prevents the rest of the code to be displayed, if i write a simple <h1>hello</h1> inside that document.write(), everything works fine....
– Mxmx88
Nov 20 '18 at 9:10
add a comment |
I Solved Writing This:
<script type="text/javascript">
if(window.innerWidth>1024){
document.write('x3Cscript language="JavaScript" type="text/javascript" charset="iso-8859-1" src="//www.intopic.it/iframe.php?cat=fonti-rinnovabili&rootcat=tecnologia&type=2&bgcolor=FFFFFF&bdcolor=FFFFFF&lcolor=666666&font=1&fontsize=13&box=1024&window=1"x3C/script>');
}else if(window.innerWidth>600){document.write('x3Cscript language="JavaScript" type="text/javascript" charset="iso-8859-1" src="//www.intopic.it/iframe.php?cat=fonti-rinnovabili&rootcat=tecnologia&type=2&bgcolor=FFFFFF&bdcolor=FFFFFF&lcolor=666666&font=1&fontsize=13&box=600&window=1"x3C/script>');}
else{
document.write('x3Cscript language="JavaScript" type="text/javascript" charset="iso-8859-1" src="//www.intopic.it/iframe.php?cat=fonti-rinnovabili&rootcat=tecnologia&type=2&bgcolor=FFFFFF&bdcolor=FFFFFF&lcolor=666666&font=1&fontsize=13&box=250&window=1"x3C/script>');}
</script>
I Solved Writing This:
<script type="text/javascript">
if(window.innerWidth>1024){
document.write('x3Cscript language="JavaScript" type="text/javascript" charset="iso-8859-1" src="//www.intopic.it/iframe.php?cat=fonti-rinnovabili&rootcat=tecnologia&type=2&bgcolor=FFFFFF&bdcolor=FFFFFF&lcolor=666666&font=1&fontsize=13&box=1024&window=1"x3C/script>');
}else if(window.innerWidth>600){document.write('x3Cscript language="JavaScript" type="text/javascript" charset="iso-8859-1" src="//www.intopic.it/iframe.php?cat=fonti-rinnovabili&rootcat=tecnologia&type=2&bgcolor=FFFFFF&bdcolor=FFFFFF&lcolor=666666&font=1&fontsize=13&box=600&window=1"x3C/script>');}
else{
document.write('x3Cscript language="JavaScript" type="text/javascript" charset="iso-8859-1" src="//www.intopic.it/iframe.php?cat=fonti-rinnovabili&rootcat=tecnologia&type=2&bgcolor=FFFFFF&bdcolor=FFFFFF&lcolor=666666&font=1&fontsize=13&box=250&window=1"x3C/script>');}
</script>
<script type="text/javascript">
if(window.innerWidth>1024){
document.write('x3Cscript language="JavaScript" type="text/javascript" charset="iso-8859-1" src="//www.intopic.it/iframe.php?cat=fonti-rinnovabili&rootcat=tecnologia&type=2&bgcolor=FFFFFF&bdcolor=FFFFFF&lcolor=666666&font=1&fontsize=13&box=1024&window=1"x3C/script>');
}else if(window.innerWidth>600){document.write('x3Cscript language="JavaScript" type="text/javascript" charset="iso-8859-1" src="//www.intopic.it/iframe.php?cat=fonti-rinnovabili&rootcat=tecnologia&type=2&bgcolor=FFFFFF&bdcolor=FFFFFF&lcolor=666666&font=1&fontsize=13&box=600&window=1"x3C/script>');}
else{
document.write('x3Cscript language="JavaScript" type="text/javascript" charset="iso-8859-1" src="//www.intopic.it/iframe.php?cat=fonti-rinnovabili&rootcat=tecnologia&type=2&bgcolor=FFFFFF&bdcolor=FFFFFF&lcolor=666666&font=1&fontsize=13&box=250&window=1"x3C/script>');}
</script>
<script type="text/javascript">
if(window.innerWidth>1024){
document.write('x3Cscript language="JavaScript" type="text/javascript" charset="iso-8859-1" src="//www.intopic.it/iframe.php?cat=fonti-rinnovabili&rootcat=tecnologia&type=2&bgcolor=FFFFFF&bdcolor=FFFFFF&lcolor=666666&font=1&fontsize=13&box=1024&window=1"x3C/script>');
}else if(window.innerWidth>600){document.write('x3Cscript language="JavaScript" type="text/javascript" charset="iso-8859-1" src="//www.intopic.it/iframe.php?cat=fonti-rinnovabili&rootcat=tecnologia&type=2&bgcolor=FFFFFF&bdcolor=FFFFFF&lcolor=666666&font=1&fontsize=13&box=600&window=1"x3C/script>');}
else{
document.write('x3Cscript language="JavaScript" type="text/javascript" charset="iso-8859-1" src="//www.intopic.it/iframe.php?cat=fonti-rinnovabili&rootcat=tecnologia&type=2&bgcolor=FFFFFF&bdcolor=FFFFFF&lcolor=666666&font=1&fontsize=13&box=250&window=1"x3C/script>');}
</script>
edited Nov 20 '18 at 9:16
answered Nov 19 '18 at 17:56
Mxmx88Mxmx88
113
113
Partially solved, now anything is visible below this piece of code, I think there's something inside the document.write() expressions that if executed, it prevents the rest of the code to be displayed, if i write a simple <h1>hello</h1> inside that document.write(), everything works fine....
– Mxmx88
Nov 20 '18 at 9:10
add a comment |
Partially solved, now anything is visible below this piece of code, I think there's something inside the document.write() expressions that if executed, it prevents the rest of the code to be displayed, if i write a simple <h1>hello</h1> inside that document.write(), everything works fine....
– Mxmx88
Nov 20 '18 at 9:10
Partially solved, now anything is visible below this piece of code, I think there's something inside the document.write() expressions that if executed, it prevents the rest of the code to be displayed, if i write a simple <h1>hello</h1> inside that document.write(), everything works fine....
– Mxmx88
Nov 20 '18 at 9:10
Partially solved, now anything is visible below this piece of code, I think there's something inside the document.write() expressions that if executed, it prevents the rest of the code to be displayed, if i write a simple <h1>hello</h1> inside that document.write(), everything works fine....
– Mxmx88
Nov 20 '18 at 9:10
add a comment |
Try:
var source_url,
script_element = document.createElement("script");
if(window.innerWidth > 1024) {
script_element.src = "1024_script_source_url";
console.log('loaded 1024 url, window width', window.innerWidth);
} else if (window.innerWidth > 600) {
script_element.src = "600_script_source_url";
console.log('loaded 1024 url, window width', window.innerWidth);
}
document.head.append(script_element);
alert('done, window width' + window.innerWidth);
You'll probably want to subscribe to window resize event so...
window.onresize = function(event) {
//do something
};
why do you declare var source_url ?
– Mxmx88
Nov 19 '18 at 16:21
add a comment |
Try:
var source_url,
script_element = document.createElement("script");
if(window.innerWidth > 1024) {
script_element.src = "1024_script_source_url";
console.log('loaded 1024 url, window width', window.innerWidth);
} else if (window.innerWidth > 600) {
script_element.src = "600_script_source_url";
console.log('loaded 1024 url, window width', window.innerWidth);
}
document.head.append(script_element);
alert('done, window width' + window.innerWidth);
You'll probably want to subscribe to window resize event so...
window.onresize = function(event) {
//do something
};
why do you declare var source_url ?
– Mxmx88
Nov 19 '18 at 16:21
add a comment |
Try:
var source_url,
script_element = document.createElement("script");
if(window.innerWidth > 1024) {
script_element.src = "1024_script_source_url";
console.log('loaded 1024 url, window width', window.innerWidth);
} else if (window.innerWidth > 600) {
script_element.src = "600_script_source_url";
console.log('loaded 1024 url, window width', window.innerWidth);
}
document.head.append(script_element);
alert('done, window width' + window.innerWidth);
You'll probably want to subscribe to window resize event so...
window.onresize = function(event) {
//do something
};
Try:
var source_url,
script_element = document.createElement("script");
if(window.innerWidth > 1024) {
script_element.src = "1024_script_source_url";
console.log('loaded 1024 url, window width', window.innerWidth);
} else if (window.innerWidth > 600) {
script_element.src = "600_script_source_url";
console.log('loaded 1024 url, window width', window.innerWidth);
}
document.head.append(script_element);
alert('done, window width' + window.innerWidth);
You'll probably want to subscribe to window resize event so...
window.onresize = function(event) {
//do something
};
answered Nov 19 '18 at 15:01
Tom StTom St
577511
577511
why do you declare var source_url ?
– Mxmx88
Nov 19 '18 at 16:21
add a comment |
why do you declare var source_url ?
– Mxmx88
Nov 19 '18 at 16:21
why do you declare var source_url ?
– Mxmx88
Nov 19 '18 at 16:21
why do you declare var source_url ?
– Mxmx88
Nov 19 '18 at 16:21
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53376983%2fneed-a-javascript-solution-to-completely-hide-a-portion-of-code-in-different-scr%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
so just document.write out the script tag after reading the page size
– epascarello
Nov 19 '18 at 14:46
I'm not sure I understand; those three snippets appear to be identical. Are you including all three in the same document? Why not just resize/style the same
p
in the css according to the min-width?– dgeare
Nov 19 '18 at 14:50
Please provide full media queries. Avoid using javascript when not necessary.
– Edwin Dijas Chiwona
Nov 19 '18 at 14:56
2
Add
max-width
to your media queries.– nvioli
Nov 19 '18 at 15:03
how can i document.write out() the code if the src it is an attribute of the <script> tag ?
– Mxmx88
Nov 19 '18 at 16:43