Where do i put _blank in this search script?
<script>
$(document).ready(function(){
$('#txtSearch').autocomplete({
source: "post_search.php",
minLength: 2,
select: function(event, ui) {
var url = ui.item.id;
if (url != '#') {
location.href = url
}
},
open: function(event, ui) {
$(".ui-autocomplete").css("z-index", 1000)
}
})
});
</script>
Instead of location.href you can try to use window.open. Your code should look like this:
window.open(url,'_blank');
Related
In my webpage i want to make a script to detect a specific extension that manipulate my code
I've already tried the following in my webpage
async function tst(){
debugger;
window.addEventListener("PassToBackground", function(evt) {
var blockedExID="bjnkkhimoaclnddigpphpgkfgeggokam";
if (!chrome.runtime) {
// Chrome 20-21
chrome.runtime = chrome.extension;
} else if(!chrome.runtime.onMessage) {
// Chrome 22-25
chrome.runtime.onMessage = chrome.extension.onMessage;
chrome.runtime.sendMessage = chrome.extension.sendMessage;
chrome.runtime.onConnect = chrome.extension.onConnect;
chrome.runtime.connect = chrome.extension.connect;
}
var runtimeOrExtension = chrome.runtime && chrome.runtime.sendMessage ?
'runtime' : 'extension';
var reponse= chrome[runtimeOrExtension].sendMessage(blockedExID,{ message: "version" },{
function (reply) {
if (reply) {
alert(reply);
}
}
});
chrome[runtimeOrExtension].sendMessage({greeting: 'hello'});
}, false);
}
but chrome.runtime is undefiled
Share Point add list item count greater than 5 show validation, is it possible with validation. If not please let me know the process.
We can use REST API to get items count by the current user, then prevent new item in new form page.
Example, add the code below into script editor web part in newform.aspx page.
<script src="https://code.jquery.com/jquery-1.12.4.min.js" type="text/javascript"></script>
<script type="text/javascript">
var listTitle="CL0902";
$(function () {
var itemCount=getItemsCountByAuthor(listTitle);
if(itemCount >= 5){
alert("You can not add item more than 5.");
window.location.href=_spPageContextInfo.webAbsoluteUrl+"/lists/"+listTitle+"/AllItems.aspx";
}
});
function PreSaveItem(){
var itemCount=getItemsCountByAuthor(listTitle);
if(itemCount >= 5){
alert("You can not add item more than 5.");
return false;
}
return true;
}
function getItemsCountByAuthor(listTitle){
var itemCount=0;
$.ajax({
url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('"+listTitle+"')/items?$select=Author/ID,ID&$expand=Author&$filter=Author/Id eq "+_spPageContextInfo.userId,
type: "GET",
async:false,
headers: {
"Accept": "application/json;odata=verbose",
},
success: function (data) {
itemCount=data.d.results.length;
},
error: function (data) {
//alert("Error");
}
});
return itemCount;
}
</script>
in chrome extension, I am creating a new html page as popup through background.js. Check the background.js code below,
chrome.contextMenus.create({
title: "share this",
contexts: ["selection"],
onclick: myFunction
});
var test0 = "Testing content Outside the myfunction";
function myFunction(data) {
var theSelection = data.selectionText;
console.log(theSelection);
chrome.tabs.query({'active': true, "lastFocusedWindow":true}, function(tabs) {
var sourceURL = tabs[0].url;
chrome.windows.create({
url: chrome.runtime.getURL('redirect.html'), type: 'popup'},
function(tab)
{
});
return record;
})
}
I have gone through getbackgroundpage function given here. I am able to access variable test0 with it but not sourceURL (as it is not in window scope).
by redirect popup window code is below,
var bg = chrome.extension.getBackgroundPage();
var sourceURL = bg.sourceURL;
var testvariable = bg.test0;
sourceURL is undefined.
Not getting a clue on how to define variables as global so that access in popup.
is there any better way, we can do it?
Dude , try to use Gogle message passing .
Little example from link before
BackgroundScript
var myFunc = function(){
//some code
}
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
if (request.messageType == "callSomeFunc") {
myFunc();
sendResponse({
status: "Function myFunc called."
});
}
//use return true for async response
return true;
});
contentScript
chrome.runtime.sendMessage({
messageType: "callSomeFunc"
},
function(response) {
// response contain {status: "Function myFunc called."}
console.log(response);
});
I have requirement where i need to create a PDF from html in node .In addition to that i must be able to add custom header and footer. Then content of the web page should be in multiple pages based on custom requirement. that is we must able to decide what content should be which page.
After searching i found some solutions like phantom , but there is no proper documentation which could help me.
I need some way to do this.
Found a solution
here , but explanation is not good enough.
I have been using https://github.com/baudehlo/node-phantom-simple module with webshot
Step I follow:-
Create HTML using the node-phantom-simple
After creating the HTML use that HTML to pass it in webshot.
var driver = require('node-phantom-simple');
var webshot = require('webshot');
driver.create({path: require('phantomjs').path, 'parameters': {'disk-cache': 'yes'}}, function (err, browser) {
return browser.createPage(function (err, page) {
return page.open(url, function (err, status) {
console.log("opened site? ", status,page.content);
return page.evaluate(File.cleanHtml, function (err, html) {
var options = {
streamType: 'pdf',
screenSize: {
width: 1200,
height: 300
},
shotSize: {
width: 1200,
height: 300
},
siteType:'html',// include this to generate PDF from html
phantomConfig: {'ssl-protocol':'any','ignore-ssl-errors': 'true'}
}
var pdfname = 'test_' + Date.now() + '.pdf';
webshot(html,pdfname,options, function(err) {
console.log("err in webshot",err);
})
});
// });
});
});
});
Here File.cleanHtml is a function I have created which is used to remove extra content from HTML.you can directly return same HTML from this function.may be something like this :)
cleanHtml: function () {
var data = $("html");
return "<html>" + data.html() + "</html>";
}
I have to pin secondary tile in my windows phone 8.1 application.
I followed the msdn tutorial : http://code.msdn.microsoft.com/windowsapps/secondary-tiles-sample-edf2a178/
It does work with internal image (ms-appx://.. ) but not with web url (http://)
working sample:
var logo = new Windows.Foundation.Uri("ms-appx:///Images/square30x30Tile-sdk.png");
var currentTime = new Date();
var TileActivationArguments = data.ad_id + " WasPinnedAt=" + currentTime;
var tile = new Windows.UI.StartScreen.SecondaryTile(data.ad_id,
data.subject,
TileActivationArguments,
logo,
Windows.UI.StartScreen.TileSize.square150x150);
tile.visualElements.foregroundText = Windows.UI.StartScreen.ForegroundText.light;
tile.visualElements.square30x30Logo = logo;
tile.visualElements.showNameOnSquare150x150Logo = true;
var selectionRect = this.element.getBoundingClientRect();
// Now let's try to pin the tile.
// We'll make the same fundamental call as we did in pinByElement, but this time we'll return a promise.
return new WinJS.Promise(function (complete, error, progress) {
tile.requestCreateForSelectionAsync({ x: selectionRect.left, y: selectionRect.top, width: selectionRect.width, height: selectionRect.height }, Windows.UI.Popups.Placement.above).done(function (isCreated) {
if (isCreated) {
complete(true);
} else {
complete(false);
}
});
});
And if I use
var logo = new Windows.Foundation.Uri(data.images[0]);
I got an invalid parameter exception.
You can take a look at the documentation for the SecondaryTile.Logo property. In it you'll see this:
The location of the image. This can be expressed as one of these schemes:
ms-appx:///
ms-appdata:///local/
You can download the image first and then set it using the ms-appdata:///local/ scheme. I'm not sure that changing the logo with something from the Internet is a good idea, though. This should be the app's logo, so it should be in the package.
I found the solution
fileExists: function (fileName) {
var applicationData = Windows.Storage.ApplicationData.current;
var folder = applicationData.localFolder;
return folder.getFileAsync(fileName).then(function (file) {
return file;
}, function (err) {
return null;
});
},
download: function (imgUrl, imgName) {
return WinJS.xhr({ url: imgUrl, responseType: "blob" }).then(function (result) {
var blob = result.response;
var applicationData = Windows.Storage.ApplicationData.current;
var folder = applicationData.localFolder;
return folder.createFileAsync(imgName, Windows.Storage.
CreationCollisionOption.replaceExisting).then(function (file) {
// Open the returned file in order to copy the data
return file.openAsync(Windows.Storage.FileAccessMode.readWrite).
then(function (stream) {
return Windows.Storage.Streams.RandomAccessStream.copyAsync
(blob.msDetachStream(), stream).then(function () {
// Copy the stream from the blob to the File stream
return stream.flushAsync().then(function () {
stream.close();
});
});
});
});
}, function (e) {
//var msg = new Windows.UI.Popups.MessageDialog(e.message);
//msg.showAsync();
});
},
var self = this;
this.download(data.images[0], data.ad_id).then(function () {
self.fileExists(data.ad_id).then(function (file) {
var logo = new Windows.Foundation.Uri("ms-appdata:///Local/" + data.ad_id);
....
I need to download the image, store it and then I can use ms-appdata:///Local