I've got a small script that detects if the user is using a certain browser
var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
if(is_chrome){
$('.ifChrome').attr('style', 'display:block;');
$('.ifChrome').html($('noscript > div').html());
};
If they are using this browser, we want to display a div tag and show the HTML from a different div tag inside.
<noscript>
<div class="note">
Your browser does not properly support the WMD Markdown Editor.<br />
Please use <a href="/about/markdown" target="_blank">Markdown<.a> to style your input.
</div>
</noscript>
<div class="hidden ifChrome note"></div>
What I'm trying to do is show the "not supported" text from inside my <noscript>
tag to users who are using this browser (because WMD Markdown doesn't work properly with it).
My existing Javascript is not working. Any help would be greatly appreciated.
I've got a small script that detects if the user is using a certain browser
var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
if(is_chrome){
$('.ifChrome').attr('style', 'display:block;');
$('.ifChrome').html($('noscript > div').html());
};
If they are using this browser, we want to display a div tag and show the HTML from a different div tag inside.
<noscript>
<div class="note">
Your browser does not properly support the WMD Markdown Editor.<br />
Please use <a href="/about/markdown" target="_blank">Markdown<.a> to style your input.
</div>
</noscript>
<div class="hidden ifChrome note"></div>
What I'm trying to do is show the "not supported" text from inside my <noscript>
tag to users who are using this browser (because WMD Markdown doesn't work properly with it).
My existing Javascript is not working. Any help would be greatly appreciated.
Share Improve this question edited Jan 2, 2011 at 5:33 Chase Florell asked Jan 1, 2011 at 22:32 Chase FlorellChase Florell 47.4k59 gold badges190 silver badges382 bronze badges 9- Are you sure it doesn't work in Chrome? It seems to work for me... – lonesomeday Commented Jan 1, 2011 at 22:36
-
The div shows, but the content of the
noscript > div
does not get displayed in the<div class="ifChrome">
... Instead it's just blank. – Chase Florell Commented Jan 1, 2011 at 22:37 - I meant that WMD Markdown seems to work. – lonesomeday Commented Jan 1, 2011 at 22:40
- Parts of it work, parts don't. I can't get the blockquote or the lists working proper. This is a known issue because of the way the Chrome regex works. – Chase Florell Commented Jan 1, 2011 at 22:41
- Can't you just put the same text inside the Chrome note? :)) – XCS Commented Jan 1, 2011 at 22:46
3 Answers
Reset to default 10This is a bit late but you can do:
var noscriptContents = $($('noscript').html());
$('.ifChrome').append(noscriptContents);
You cannot access the content of a noscript-element using javascript in chrome. So you'll have to find a different approach that doesn't use a noscript-element. Read more about that problem here
<noscript id="noscript-main">
<div id="div-inside-noscript">
<span>Your content here</span>
</div>
<div>1</div>
<div class="no-action">2</div>
</noscript>
<div id="show"></div>
<script>
var noscript_main = $(`#noscript-main`);
var noscript_main_text = noscript_main.text();
$.each($(noscript_main_text),function(k,v){
var obj = $(v);
// if you want get the id of element:
if( obj.get(0).tagName == `DIV` ) {
console.log( obj.prop(`id`));
}
//if you want display div-inside-noscript inside div#show
if(obj.prop(`id`) == `div-inside-noscript` ){
var obj_html = obj.html();
$(`#show`).html(obj_html);
}
});
//if you want remove noscript tag
noscript_main.remove();
</script>