admin管理员组文章数量:1242839
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>
本文标签:
版权声明:本文标题:javascript - jQuery: How can I get the HTML from inside NoScript to display in a differend div tag? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1740158716a2234021.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论