Good day.
Is it possible, with userscript , to send another page (not the current one) in background mode?
Specialist. libraries or alternative ideas of window.open () , or in general any ideas for solving such a problem?
|
2 answers
Create a hidden frame, load the page into it. If the page is in the same domain where UserJS is loaded, then simply refer to iframe.contentDocument
var iframe= document.createElement('iframe'); iframe.style.display= "none"; iframe.src= "/"; iframe.onload= function(){ console.log(iframe.contentDocument.body.innerHTML); }; document.body.appendChild(iframe); - @ReinRaus, yes. The same domain, I just don’t want to incite the eyes of the user, and myself too: pop-up windows (it pops up every 10-15 minutes, by default). Can you send a link to the guide or a working example in response? What could I thank you for? ) - HA3IK
|
Using jQuery :
Connect it if not:
UserScript: // @require https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.4/jquery.min.js Download the desired page ajax th:
$.ajax({ url: '/dir/other-file.htm', dataType: "text", success: function (function (data, status, xhr) { // парсим текст - $(data) // но так как html в тексте может быть невалидным // то завернем весь текст в div var temp = $('<div/>', {html: data}); // далее работаем как с обычным jQuery Node temp.find('.myclass').text(); // или each() и тд } }); |