I am trying to make it so when someone goes onto my codepen --> https://codepen.io/Mike-was-here123/pen/gXMrJO , the window opens itself. Basically a infinite loops opening and closing itself, this is my JS/ jQuery code:
I added comments in the code on the codepen.
$(document).ready(function() {
if (document.URL !== "https://codepen.io/Mike-was-here123/full/ooLxmQ/") {
window.open("https://codepen.io/Mike-was-here123/full/ooLxmQ/");
}
var one = 1;
if (1 === 1) {
window.open("https://codepen.io/Mike-was-here123/full/ooLxmQ/");
one += 1;
}
if (one !== 1) {
window.close();
}
});
Why doesn't the window open?
Also if i wanted to close the current tab because i just opened a new one, would i just use window.close()?
If you want to open an infinite number of web pages, just do this:
while (true) {
window.open("insert web page");
}
Related
I'm writing a chrome extension and from that extension i want to click on a particular anchor tag in a webpage on a particular website.
let helpRequestButton = document.querySelectorAll(".live-doubt-item-resolve.ng-scope a");
Using this query selector i'm able to get the anchor tag from the web page which looks like.
<a data-ga-label="resolve_now_live" data-ga-action="clicked" ng-if="helpRequestObj.item_type === 'Topic'" ng-click="claimLiveRequest($event, true, helpRequestObj.id)" target="_blank" class="content-heading ng-scope" data-ga-category="HelpRequestDashboardLive"> </a>
I just want to click on this tag using java script.
But helpRequestButton.click() dosent work.
I have tried the same solution with jQuery(did'nt work).
Also i tried to search a lot on web on how to simulate a mouse click and none of the solutions worked uptill now.
Just for refrence i'm giving the code snippet of my extension what chrome would call one the webpage is loaded. The button which i have to click is present on the web page.
let timeOut;
function stopTimeout() {
clearTimeout(timeOut);
}
function checkIncomingHelpRequests() {
let helpRequestButton = document.querySelectorAll(".live-doubt-item-resolve.ng-scope a");
console.log(helpRequestButton[0]);
if (helpRequestButton.length > 0) {
> ***// This is the place i want to click the button.***
// helpRequestButton.
//helpRequestButton.click();
}
}
function selectTag() {
// var object = document.querySelector(".main-class");
// console.log(object);
let liButton = document.querySelectorAll(".pointer.tab.ga-event-tracker")[0];
//let liButton = $("li.pointer.tab.ga-event-tracker")[0];
//console.log(liButton);
if (liButton !== undefined) {
liButton.click();
checkIncomingHelpRequests();
}
timeOut = setTimeout("selectTag()", timeOutInterval);
}
$(document).ready(function () {
selectTag();
});
Please help me. Thanks in advance.
I have a chrome extension which does the following:
When a user copies a word, a popup window opens with a specific url, searching the word in a dictionary. If the popup window already exists, it removes it and recreates it (if you ask why, the answer is: because chrome.windows.update() does not take URL as a parameter so I cannot simply update the window with a new URL).
The problem is: If the user is in another application (like MS Word) and copies a word, when the user clicks on the taskbar icon of the browser (chrome) popup window to bring it on the front, then Chrome does not paint the content of the page, it only displays the title of the page. If the user closes with the X button the popup window though, there is no problem. It happens only if the user just clicks back on MS Word to continue writing and then copies another word, without previously manually closing the popup window. The code is:
g_iIntervalID = setInterval(getClipboardText, 500);
function getClipboardText() {
g_oTA.select();
g_oBG.document.execCommand("Paste");
var clipText = g_oTA.value;
if (g_bOpenWindow) {
clipText = cleanWord(trim(clipText));
if (clipText != "" && clipText.length <= 64 && clipText != g_sPrevClipText && clipText != g_sWord) {
if (g_bClipFirstTime == false) {
g_sWord = clipText;
openLink();
}
g_sPrevClipText = clipText;
}
g_bClipFirstTime = false;
}
}
function openLink() {
chrome.windows.getAll(onWindowsQueryReply);
}
function onWindowsQueryReply(windows) {
var bWindowFound = false;
if (chrome.runtime.lastError) {
console.log(chrome.runtime.lastError);
} else {
if (g_iCreatedWindowID != 0 && windows.length > 0) {
var wnd;
for (var i = 0; i < windows.length; i++) {
wnd = windows[i];
if (g_iCreatedWindowID == wnd.id) {
bWindowFound = true;
var r = chrome.windows.remove(g_iCreatedWindowID, function() {
CreateWindow();
return;
});
}
}
}
if (bWindowFound === false) CreateWindow();
}
}
function CreateWindow() {
clearInterval(g_iResizeIntervalID);
var createData = {
state: "normal",
url: "https://www.example.com/search.php?word=" + g_sWord,
type: "popup",
top: g_iWinT,
left: g_iWinL,
height: g_iWinH,
width: g_iWinW
};
var creating = chrome.windows.create(createData, onWinCreated);
}
function onWinCreated(win) {
if (chrome.runtime.lastError) {
console.log(chrome.runtime.lastError);
} else {
g_iCreatedWindowID = win.id;
//console.log(g_iWinW + "#" + g_iWinH + "#" + g_iWinT + "#" + g_iWinL + "###The panel has been created"+JSON.stringify(win));
var updateData = {
state: "normal",
top: g_iWinT,
left: g_iWinL,
drawAttention: true,
focused: true
};
var updating = chrome.windows.update(win.id, updateData);
g_iResizeIntervalID = setInterval(getWindowSize, 200);
}
}
Steps:
User is using an app like MS Word
User double clicks a word and ctrl-c or right-click copies it.
When this happens then openLink() runs
The extension removes the current popup window (if it exists) and then creates a new one with a URL
A small icon for the new popup window appears flashing in the taskbar
The first time, the popup window comes automatically in front. The user reads then necessary information
The user clicks back on MS Word to continue work
The user marks another word and copies it
The extension opens another new popup window. This window for some reason does not come on front like the first time, but this is not the main problem. The user has to click its taskbar icon to bring it in front.
The user clicks the icon of the popup window in the taskbar in order to bring it to front.
The popup window comes to front, but it displays a blank page (except for the title).
Comments:
Chrome paints the contents ONLY if I click on the title bar and drag the window a bit OR if I hover the mouse on the icon of the pop up window in the taskbar so that a preview is displayed.
If the user closes the popup window with the X button, then the problem does not arise the next time he copies a word (plus the popup window goes automatically in front/focus, so none of the problems appears).
I have tried many things:
inserting async delays with setTimeout before creating and updating the pop window
repositioning and resizing the popup window in onWinCreated()
repositioning and resizing after the first chrome.windows.update()
But all these efforts in trying to trigger/force Chrome paint the window, have failed. Am I doing something wrong? How can I fix this issue? Also, why the first time when the popup opens, it comes automatically in front (or if I closed the previous popup manually)? But when it gets programmatically removed, it does not? Can this also be solved?
Thank you in advance
I created a menu in wordpress that both contains anchorlinks to different sections on the startpage, and links to other pages:
But when I navigate to another page (ex "Jobs"), and from there try to navigate in manu to a section on startpage - anchorlinks doesn't work because it needs the full URL to guide user back to startpage and then jump down to the section i clicked. But when I change anchorlinks to full url:
..it will allways reload, even if i'm on startpage because I have the full url. How do i create a menu that will only have section URL (ex "#meetups") on the startpage, and full URL (ex "/hip#meetups") when I'm on another page.
Can I build a javascript or PHP function for this?
I really got stuck here and will be incredibly thankful for any input
I made a jQuery function that will alter menu-link-attr/url depending on browser.location:
var x = location.pathname;
if(x === '/hip/jobs/'){
var findLink = $('.menu-item-type-custom').find('a');
for (var i = 0; i < findLink.size(); i++) {
var attri = findLink.eq(i).attr('href');
findLink.eq(i).attr('href', "http://localhost:3000/hip/" + attri);
}
} else {
console.log('error! ' + x);
}
I am trying to combine ContentFlow (http://jacksasylum.eu/ContentFlow/) and ColorBox (http://www.jacklmoore.com/colorbox/): when the user clicks on an image in ContentFlow I want an HTML page to be displayed in ColorBox.
I have tried using the code provided by the ColorBox examples' section to no avail. The HTML page is loaded by the browser as a normal link (not in ColorBox.)
I have even tried creating a ContentFlow addon (using the LightBox addon as an example) without any luck - nothing is displayed, not even simple images:
onclickActiveItem: function (item) {
var content = item.content;
if (content.getAttribute('src')) {
if (item.content.getAttribute('href')) {
item.element.href = item.content.getAttribute('href');
}
else if (! item.element.getAttribute('href')) {
item.element.href = content.getAttribute('src');
}
if (item.caption)
item.element.setAttribute ('title', item.caption.innerHTML);
colorbox.show(item.element);
}
}
Edited on 01/Oct/2013
The problem only manifests itself when an item contains an href. To prove this I changed the code above to show a static web page:
$.colorbox({open:true, href:"http://mysite.gr/colorbox/content/static.html"});
It the item is just a simple image the static web page is displayed in ColorBox. But if the item contains an href to the web page I want displayed in ColorBox the browser follows the link and loads the specified page. Any ideas on how to stop this from happening?
Thank you in advance for your help!
I have finally solved the problem I have described in my question. The solution involves creating a ContentFlow addon as follows:
new ContentFlowAddOn ('colorbox', {
init: function () {
var colorboxBaseDir = this.scriptpath+"../colorbox/";
var colorboxCSSBaseDir = colorboxBaseDir;
var colorboxImageBaseDir = colorboxBaseDir;
this.addScript(colorboxBaseDir+"jquery.colorbox.js");
this.addStylesheet(colorboxCSSBaseDir+"example3/colorbox.css");
},
ContentFlowConf: {
onclickInactiveItem: function (item) {
this.conf.onclickActiveItem(item);
},
onclickActiveItem: function (item) {
var content = item.content; // ContentFlow's content class
var theItem = item.item; // ContentFlow's item class - if you need access to it
var hrefToDisplay = '';
if (content.getAttribute('src')) {
if (content.getAttribute('href')) {
hrefToDisplay = item.content.getAttribute('href');
}
else if (!item.element.getAttribute('href')) {
hrefToDisplay = content.getAttribute('src');
}
$.colorbox({iframe:true, href:hrefToDisplay, title:item.caption});
}
}
}
});
The secret is to open the HTML page in an iframe.
Hope this helps!
On one of our pages the user has the option to print a selected list of html pages. This is how it is at the moment
var rowcount = FrmMain.RowCount;
var frame = FrmMain.Frame;
for(i=1;i<=rowcount;i++)
{
var obj = FrmMain.elements("chk_" + i);
if(obj.checked)
{
frame.src = FrmMain.elements("hpath" + i).value;
window.frames[frame.id].focus();
window.frames[frame.id].print();
}
}
Now this works fine. The problem is that on each loop the print dialog box is displayed and the user has to click print.
Basically, what I'm asking is whether that is a way to supress this dialog. It must appear at the first time but hide thereafter. Some thing like below
var show = true;
...
{
...
{
...
if(show)
{
window.frames[frame.id].focus();
window.frames[frame.id].print();
show = false;
}
else
{
window.frames[frame.id].focus();
window.frames[frame.id].printwithoutdialog();
}
}
}
I hope I've been clear. Thanks in advance.
For security / privacy reasons, this is impossible.
Otherwise, ads would automatically print their brochures.
Instead, you can combine all of the pages into a single frame.
Some browsers have an option bypass the dialog, but it can't be done in javascript.